package com.jiazhong.schedule.dao.impl;

import com.jiazhong.schedule.dao.BaseDao;
import com.jiazhong.schedule.dao.SysUserDao;
import com.jiazhong.schedule.pojo.SysUser;

import java.util.List;

public class SysUserImpl  implements SysUserDao {
    @Override
    public int addSysUser(SysUser sysUser) {
        BaseDao baseDao=new BaseDao();
        String sql="insert into sys_user values (null,?,?)";
        return baseDao.baseUpdate(sql,sysUser.getUsername(),sysUser.getUserPwd());


    }

    @Override
    public SysUser login(String name) {
        BaseDao baseDao=new BaseDao();
        String sql="select uid,username, user_pwd userPwd from sys_user where username = ?";
        List <SysUser> sysUsers= baseDao.baseQuery(SysUser.class,sql,name);
        return null != sysUsers && sysUsers.size() > 0 ? sysUsers.get(0) : null;
        /*首先检查 sysUsers 列表不为 null 且包含至少一个元素
        如果条件成立，返回列表中的第一个用户对象 (sysUsers.get(0))*/
    }
}
